package cn.wolfcode.consumer._03_consumer;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class Consumer {
    public static void main(String[] args) throws Exception{

        //创建一个拉取消息的消费者对象
        DefaultMQPullConsumer pull = new DefaultMQPullConsumer("wolfcode-consumer");
        //设置名字地址
        pull.setNamesrvAddr("127.0.0.1:9876");
        //启动消费者
        pull.start();
        PullResult pullResult = pull.pull(new MessageQueue("04-hello", "broker-a", 0), "*", 0, 10);

        List<MessageExt> list = pullResult.getMsgFoundList();
        for (MessageExt messageExt : list) {
            System.out.println("消息是"+ new String (messageExt.getBody()));
        }

    }
}
